<template>
  <el-form-item label="商家名称">
    <el-select
      v-model="model"
      placeholder="请选择商家"
      clearable
    >
      <el-option
        v-for="item in list"
        :key="item.id"
        :label="item.storeName"
        :value="item.id"
      />
    </el-select>
  </el-form-item>
</template>

<script lang="ts" setup>
import {request, post} from "@/utils/request";
import ApiResult from "@/api/base/ApiResult";
import {ISupplierItem} from "@/components/goodsCenter/types/goodsSupplier";

const props = withDefaults(defineProps<{
  url?: string,
  data?: any
}>(), {
  url: 'merchant/member/goods/getStore',
  data: {
    defaultStore:-1,
  },
})

const emits = defineEmits(['change'])

const model = ref()
const list = ref<ISupplierItem[]>()
const getList = async () => {
  const rs:ApiResult<ISupplierItem[]> = await request(props.url, props.data)

  if (rs.code === 200) {
    list.value = rs.payload ?? []
  }
}

watch(model, (newValue) => {
  emits('change', {selected: newValue, list})
})

onMounted(() => {
  getList()
})
</script>

<style scoped lang="scss">

</style>
